package top.lishuoboy.knife4j.swagger3_0_10.config;

import cn.hutool.core.map.MapUtil;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import lombok.extern.slf4j.Slf4j;
import org.springdoc.core.GroupedOpenApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import top.lishuoboy.dependency.base.json.HuJsonUtil;

@Slf4j
@Configuration
public class SwaggerConfig {

    @Bean
    public OpenAPI openAPI() {
        OpenAPI apiInfo = new OpenAPI();
        log.warn("默认 apiInfo=={}", HuJsonUtil.toJsonPrettyStr(apiInfo));
        /**
         * 默认值
         * apiInfo=={
         * "components": null,
         * "extensions": null,
         * "externalDocs": null,
         * "info": null,
         * "jsonSchemaDialect": null,
         * "openapi": "3.0.1",
         * "paths": null,
         * "security": null,
         * "servers": null,
         * "specVersion": "V30",
         * "tags": null,
         * "webhooks": null
         * }
         */

        return new OpenAPI()
            .info(new Info()
                .version("1.0")
                .title("标题Api Documentation")
                .description("描述Api Documentation")
                .termsOfService("服务条款网址urn:tos")
                .license(new License().name("许可Apache 2.0")
                    .url("许可证网址http://www.apache.org/licenses/LICENSE-2.0"))
                .contact(new Contact().name("小石头").url("https://lishuoboy.blog.csdn.net/").email("lishuoboy@qq.com"))
                .extensions(MapUtil.<String, Object>builder().put("博客名", "石头的茅坑").build())

            );
    }

    /**
     * 分组研究
     */
    @Bean
    public GroupedOpenApi userApi() {
        String[] paths = {"/**"};
        String[] packagedToMatch = {"top.lishuoboy.knife4j.swagger3_0_10.controller"};
        return GroupedOpenApi.builder().group("用户组")
            .pathsToMatch(paths)
//            .addOperationCustomizer((operation, handlerMethod) -> {
//                return operation.addParametersItem(new HeaderParameter().name("groupCode").example("测试").description("集团code").schema(new StringSchema()._default("BR").name("groupCode").description("集团code")));
//            })
            .packagesToScan(packagedToMatch).build();
    }


}